package com.kiwilss.aopdemo.ui.livedata

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.Transformations
import androidx.lifecycle.ViewModel

/**
 * @author : Administrator
 * e-mail : kiwilss@163.com
 * time   : 2021/02/02
 *  desc   :
 */
class TestViewModel: ViewModel() {
    //传值
    var mCurrent: MutableLiveData<String>? = null
    get() {
        if (field == null){
            field = MutableLiveData()
        }
        return field
    }
    //转换
    var liveDataMap: LiveData<Int>  = Transformations.map<String,Int>(mCurrent!!){
        input: String -> input.length
    }

    var liveDataSwitch: LiveData<String>  = Transformations.switchMap<String,String>(mCurrent!!){
        input: String? -> MutableLiveData<String>().also { it.value = input!!.toLowerCase() }
    }

}